/**
 * @file       st7789.h
 * @author     wangbing
 * @email      mz8023yt@163.com
 * @version    V1.0
 * @date       2022-03-08
 * @brief      ips lcd panel drvier
 */

#ifndef _ST7789_H_
#define _ST7789_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#ifndef LOW
#define LOW 0
#endif

#ifndef HIGH
#define HIGH 1
#endif

#define RGB565_WHITE   0xFFFF
#define RGB565_BLACK   0x0000
#define RGB565_BLUE    0x001F
#define RGB565_BRED    0XF81F
#define RGB565_GRED    0XFFE0
#define RGB565_GBLUE   0X07FF
#define RGB565_RED     0xF800
#define RGB565_MAGENTA 0xF81F
#define RGB565_GREEN   0x07E0
#define RGB565_CYAN    0x7FFF
#define RGB565_YELLOW  0xFFE0
#define RGB565_BROWN   0XBC40
#define RGB565_BRRED   0XFC07
#define RGB565_GRAY    0X8430

struct cmds {
	uint8_t cmd;
	uint8_t dats[16];
	uint8_t nums; // 0xff = end of cmds.
};

/**
 * @brief ST7789
 */
struct st7789 {
	struct {
		struct {
			int width;
			int height;

			/* TODO 这两个变量删掉会导致屏幕不显示，很神奇 */
			int xshift;
			int yshift;
		} fix;
		struct {
			int orien;
		} var;
	} cfg;
	struct {
		void (*i80_reg_write)(uint8_t cmd, uint8_t* dat, int len);
		void (*i80_color_write)(uint8_t cmd, uint8_t* dat, int len);
		void (*msleep)(int ms);
		void (*reset)(int val);
		void (*backlight)(int val);
	} ops;
};

void st7789_init(struct st7789* lcd);
void st7789_rect_fill(struct st7789* lcd, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t* color);

#ifdef __cplusplus
}
#endif

#endif
